package top.sdwu_top.kbase.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;
import top.sdwu_top.kbase.entity.KbaseRolePermission;
import top.sdwu_top.kbase.mapper.KbaseRolePermissionMapper;
import top.sdwu_top.kbase.service.IKbaseRolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限 服务实现类
 * </p>
 *
 * @author zhipeng.duan@nvr-china.com
 * @since 2020-02-20
 */
@Service
public class KbaseRolePermissionServiceImpl extends ServiceImpl<KbaseRolePermissionMapper, KbaseRolePermission> implements IKbaseRolePermissionService {


    @Override
    public List<String> getUrlListByRoleId(String roleId) {
        QueryWrapper<KbaseRolePermission> qw = Wrappers.query();
        qw.eq("ROLE_ID", roleId);
        List<KbaseRolePermission> permissionList = super.list(qw);
        if (CollectionUtils.isEmpty(permissionList)) {
            return Lists.newArrayListWithExpectedSize(0);
        }
        return permissionList.parallelStream().map(KbaseRolePermission::getPath).collect(Collectors.toList());
    }
}
